﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Nirvana
{
    public abstract class PassEvent : MonoBehaviour
    {
        private static List<RaycastResult> rayList = new List<RaycastResult>();
        private bool isPass;

        protected void PassEventDown<T>(PointerEventData point, ExecuteEvents.EventFunction<T> function) where T: IEventSystemHandler
        {
            if (this.isPass) return;
            rayList.Clear();
            EventSystem.current.RaycastAll(point, rayList);
            this.isPass = true;
            try
            {
                var go = point.pointerCurrentRaycast.gameObject;
                for (int i = 0; i < rayList.Count; i++)
                {
                    if (rayList[i].gameObject != gameObject)
                    {
                        ExecuteEvents.Execute<T>(rayList[i].gameObject,point, function);
                        break;
                    }
                }

            }
            finally
            {
                this.isPass = false;
            }


        }

    }
}

